from decimal import Decimal
goods = {'F00001':{'name':'苹果','price':1.2},'F00002':{'name':'香蕉','price':5.5}}
buygoods = {}

# 输入exit可随时退出

# 查看商品信息
def see_goods():
    print("商品信息为：")
    for i,j in goods.items():
        print(f"编号:{i} 商品信息为：{j}")


# 查看购买商品信息
def see_buy_goods():
    print("您购买的商品信息为:")
    for i, j in buygoods.items():
        print( f"{i}:{j}",end="  ")
    print("\n")

# 根据商品编号购买商品，检测余额是否足够，够就扣款，不够就提醒
def buy_goods():
    n = int(input("请输入您要购买的商品种类数："))
    if n == 'exit':
        print("购物车商品数量为0")
        exit()
    for i in range(n):
        num = input("请输入您想要购买的商品的商品编号：")
        if num == 'exit':
            print("购物车商品数量为0")
            exit()
        if num in goods.keys():
            enough_money1 = enough_money - float(goods[num]["price"])
            if enough_money1 >= 0:
                print(f"您的余款为：{enough_money1}")
                buygoods.update(goods[num])
            else:
                print("余额不足，请充值........")
        else:
            print("商品不存在，请重新输入：")
        see_buy_goods()

user_name = input("请输入用户名：")
if user_name == 'exit':
    print("购物车商品数量为0")
    exit()
keyward = input("请输入用户密码：")
if keyward == 'exit':
    print("购物车商品数量为0")
    exit()
if user_name == "root" and keyward == "123456":
    enough_money = float(input("请输入您的预算信息："))
    if keyward == 'exit':
        print("购物车商品数量为0")
        exit()
    see_goods()
    buy_goods()
else:
    print("信息输入无效，请重新输入！")

